package hang.study.uistudy;

import android.app.Activity;
import android.os.Bundle;
import android.os.Message;
import android.widget.TextView;

import android.os.Handler;

import java.util.Timer;
import java.util.TimerTask;


/**
 * Created by hang on 2015-8-25.
 */
public class TestFrameActivity extends Activity {

    private int currentColor = 0;

    final int[] colors = new int[]{
            R.color.color1,
            R.color.color2,
            R.color.color3,
            R.color.color4,
            R.color.color5,
            R.color.color6,
            R.color.color7,
            R.color.color8
    };

    final int[] names = new int[]{
            R.id.view1,
            R.id.view2,
            R.id.view3,
            R.id.view4,
            R.id.view5,
            R.id.view6,
            R.id.view7,
            R.id.view8
    };

    TextView[] views = new TextView[names.length];

    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            if(msg.what == 0x123){
                for(int i = 0; i < views.length; i++){
                    views[i].setBackgroundResource(colors[(i+currentColor)%views.length]);
                }
            }
            super.handleMessage(msg);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test_frame_main);
        for(int i = 0; i < views.length; i++){
            views[i] = (TextView)findViewById(names[i]);
        }

        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                handler.sendEmptyMessage(0x123);
            }
        },0,200);
    }
}
